<?php
class HomeController extends AppController {

	var $name = 'Home';
	var $helpers = array('Time', 'Post', 'Lemur');

        function beforeRender() {
        }

	function index() {
		if ($this->layout === 'rhrnru') {
			$this->rhrnindex();
			$this->render('rhrnindex');
		} elseif ($this->layout === 'lemuryru') {
			$this->lemuryindex();
			$this->render('lemuryindex');
		}
	}

	function rhrnindex() {
		$this->loadModel('Article');
		$this->paginate = $this->Article->pagianteConditions();
		$data['articles'] = $this->paginate('Article');
		//$data['articles'] = $this->Article->indexData();
		$data['articleTags'] = $this->Article->getTags();
		$data['rhcut'] = 'cut';

		if (isset($data)) {
			$this->set($data); # pr ($data);
		}
	}

	function lemuryindex() {
		$uid = $this->Auth->user('id');
		if ($uid) {
			$this->loadModel('User');
			$uData = $this->User->getData($uid);
//pr ($uData);
			if (!empty($uData['UsersSoctype']['soctype_id'])) {
				$uCond = $this->User->userListConditions($uData);
				$socID = $uData['UsersSoctype']['soctype_id'];

				$this->loadModel('SearchOption');
				$searchConditions = $this->SearchOption->getSearchConditions($uid);
				
				if (!empty($searchConditions)) {
					$uCond = array_merge($searchConditions, $uCond);
				}

				$this->loadModel('SearchRelation');

				$relCond = $this->SearchRelation->getConditions($uid);
				if (!$relCond) {
					$relCond['Socrelation.percent >'] = 70;
				}

				$this->loadModel('Soctypesrel');
				$data['typeRels'] = $this->Soctypesrel->getTypeRelations($socID, $relCond);
				
				$uFields = array();

				$uCond['UsersSoctype.soctype_id'] = array_keys($data['typeRels']);
				$uCond['UsersSoctype.status'] = 1;
				
				$this->paginate = array('conditions'=>$uCond, 'fields'=>$uFields, 'limit'=>9, 'order' => 'User.created DESC');
				$data['usersList'] = $this->paginate('User');
			}
		}
		
		if (!isset($socID)) {
			$this->loadModel('Socdesc');
			$data['socDesc'] = $this->Socdesc->getDesc();
		}
		
		if (isset($data)) {
			$this->set($data);
		}
	}
}
?>
